import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()],
    build: {
      outDir: 'dist', // 指定主进程构建输出目录
      lib: {
        entry: resolve(__dirname, 'src/main.js'),
        formats: ['cjs']
      }
    }
  },
  preload: {
    plugins: [externalizeDepsPlugin()],
    build: {
      outDir: 'dist/preload',
      lib: {
        entry: resolve(__dirname, 'src/preload.js'),
        formats: ['cjs']
      }
    }
  },
  renderer: {
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src')
      }
    },
    plugins: [vue()],
    build: {
      outDir: 'dist/renderer',
      // 禁用不必要的Tree Shaking以确保所有组件都被包含
      rollupOptions: {
        output: {
          // 确保文件名稳定，便于调试
          entryFileNames: '[name].js',
          chunkFileNames: 'assets/[name].js',
          assetFileNames: 'assets/[name].[ext]'
        },
        // 确保路由和组件不被错误地Tree Shaking
        preserveEntrySignatures: 'strict'
      },
      // 禁用CSS代码分割以确保样式完整
      cssCodeSplit: false
    },
    // 确保开发工具在生产环境中也能使用
    optimizeDeps: {
      include: ['vue', 'vue-router', 'pinia']
    }
  }
})
